﻿using System;
using System.IO;
using IWshRuntimeLibrary;

namespace Useful
{
    public class Shortcut
    {
        public static void CreateOnDesktop(string fileName, string linkName, string description)
        {
            WshShell shell = new WshShell();

            string link = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), linkName);

            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(link);
            shortcut.Description = description;
            shortcut.TargetPath = fileName;
            shortcut.Save();
        }

        public static string GetDesktopShortcut(string linkName)
        {
            string link = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), linkName);

            if (System.IO.File.Exists(link))
                return link;
            else
                return null;
        }

        public static void DesktopShortcutDelete(string linkName)
        {
            System.IO.File.Delete(linkName);
        }

        public static void CreateMainMenuShortcut(string fileName, string linkName, string description, string subMenu)
        {
            WshShell shell = new WshShell();

            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), subMenu);
            string link = Path.Combine(path, linkName);

            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(link);
            shortcut.Description = description;
            shortcut.TargetPath = fileName;
            shortcut.Save();
        }

        public static string GetMainMenuShortcut(string subMenu, string linkName)
        {
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), subMenu);
            string link = Path.Combine(path, linkName);

            if (System.IO.File.Exists(link))
                return link;
            else
                return null;
        }

        public static void MainMenuShortcutDelete(string linkName)
        {
            System.IO.File.Delete(linkName);
        }

        public static string GetDesktopShortcutFileName(string linkName)
        {
            string link = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), linkName);

            return link;
        }
    }
}
